package com.zjitc.controller;

import com.track.Track;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;


/**
 * Create by IntelliJ IDEA
 *
 * @author: lhl
 * @date-Time: 2018/5/6 0006
 * @description:
 */
@Controller
public class TrackControl {

    public String changArrCode(String s) {
        String[] arr1 = new String[]{"顺丰速运", "百世快递", "中通快递", "申通快递", "圆通速递",
                "韵达速递", "邮政快递包裹", "EMS", "京东物流", "快捷快递"};
        String[] arr2 = new String[]{"SF", "HTKY", "ZTO", "STO", "YTO",
                "YD", "YZPY", "EMS", "JD", "FAST"};
        String s1 = null;
        for (int i = 0; i < arr1.length; i++) {
            if (s.equals(arr1[i])) {
                s1 = arr2[i];
            }
        }
        return s1;
    }

    @RequestMapping(value = "/trackQuery", produces = "text/html; charset=UTF-8")
    @ResponseBody
    public String trackQruey(@RequestParam(name = "company") String company,
                             @RequestParam(name = "orderId") String orderId) {
        String s = changArrCode(company);
        Track api = new Track();
        String result = null;
        try {
            result = api.getOrderTracesByJson(s, orderId);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return result;
    }
}
